package com.quanyan.stadium.service.gameLevelScore.utils;

import com.quanyan.stadium.constants.GameConstants;

import java.math.BigDecimal;

/**
 * Created by xiaoxiao on 16/12/21.
 */
public class GameLScoreUtils {

    public static double DEFAULT_K = 20.00;
    public static double DEFAULT_G = 1.00;

    public static double WIN_VALUE = 1.00;
    public static double TIE_VALUE = 0.50;
    public static double LOSE_VALUE = 0.00;

    /**
     * 获取We的值,根据比赛双方的等级分
     *
     * @param ownLScore 己方等级分
     * @param oppLScore 对方等级分
     *
     * */
    public static double getWe(double ownLScore, double oppLScore) {
        return new BigDecimal(1.00/(1.00+Math.pow(10.00, (oppLScore-ownLScore)/400.00))).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    /**
     * 获取K值,根据比赛双方的等级分
     *
     * */
    public static double getK() {
        return DEFAULT_K;
    }


    /**
     * 获取W值,根据比分差值的大小
     *
     * @param scoreDiff 比分差值
     *
     * */
    public static double getW(int scoreDiff) {
        if (scoreDiff > 0) {
            return WIN_VALUE;
        }else if (scoreDiff < 0) {
            return LOSE_VALUE;
        }else {
            return TIE_VALUE;
        }
    }


    /**
     * 获取输赢状态, 根据比分差值的大小
     *
     * @param scoreDiff 比分差值
     *
     * */
    public static Byte getGameResult(int scoreDiff) {
        if (scoreDiff > 0) {
            return GameConstants.SCHEDULE_WIN;
        }else if (scoreDiff < 0) {
            return GameConstants.SCHEDULE_LOSE;
        }else {
            return GameConstants.SCHEDULE_TIE;
        }
    }


    /**
     * 获取G的值,根据比赛双方的等级分
     *
     * @param categoryId 栏目id
     * @param goalDifference 净胜球
     *
     * */
    public static double getG(int categoryId, int goalDifference) {

        if (categoryId == GameConstants.CATEGORY_ID_FOOTBALL) {
            return (11.0+goalDifference)/8.0;
        }
        return DEFAULT_G;
    }

    /**
     * 获取等级分增量
     *
     * @param a
     * @param b
     *
     * */
    public static double getLScoreIncrement(double a, double b) {
        return new BigDecimal(a-b).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}
